package org.springblade.modules.repair.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.repair.entity.BuildingExt;
import org.springblade.modules.repair.mapper.BuildingExtMapper;
import org.springblade.modules.repair.service.IBuildingExtService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 楼盘信息 服务实现类
 *
 * @author ysq
 * @since 2023-08-29
 */
@Service
public class BuildingExtServiceImpl extends BaseServiceImpl<BuildingExtMapper, BuildingExt> implements IBuildingExtService {


	@Override
	public Integer getBuildingRescueTime(Long buildingId, Date rescueTime) {
		BuildingExt buildingExt = this.getOne(Wrappers.<BuildingExt>lambdaQuery().eq(BuildingExt :: getBuildingId, buildingId), false);
		if (Func.isEmpty(buildingExt)) {
			return null;
		}

		if (buildingExt.getRescueTime() == 0) {
			return 30;
		}

		/**
		 * 白天：06：00 —— 18：00
		 * 晚上：18：00 —— 06：00
		 */
		int rescueHour = DateUtil.hour(rescueTime, true) + DateUtil.minute(rescueTime)/100 + DateUtil.second(rescueTime)/10000;
		if (rescueHour >= 6 && rescueHour <= 18) {
			return buildingExt.getRescueDaytime();
		} else {
			return buildingExt.getRescueNight();
		}
	}
}
